package day_2022_9_to_12.Day;

import java.util.ArrayList;
import java.util.List;

/**
 * @author haomin
 * @date 2022/09/11 10:29
 **/
public class Day9_3_Num6177_PartitionString {
    class Solution {
        public int partitionString(String s) {
            if(s.length() == 0) return 0;
            if(s.length() == 1) return 1;
            if(s.length() == 2) return s.charAt(0) == s.charAt(1) ? 2 : 1;

            List<String> list = new ArrayList<>();
            int l = 0, r = 1;
            String str = "";
            while(r < s.length()){
                str = s.substring(l, r);
                if(str.contains(Character.toString(s.charAt(r)))){
                    list.add(str);
                    l = r;
                    r++;
                }else{
                    r++;
                }
            }
            list.add(new String(s.substring(l, r)));
            return list.size();

        }
    }
}